package cn.wolfcode.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerService;
@Service
public class CustomerServiceImpl implements ICustomerService{

	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public void saveOrUpdate(Customer entity) {
		if (entity.getId() == null) {
			//自动录入时间
			entity.setInputTime(new Date());
			//默认潜在客户
			entity.setStatus(0);
			//设置销售
			Employee seller = new Employee();
			seller.setId(1L);
			entity.setSeller(seller);
			entity.setSeller(seller);
			customerMapper.insert(entity);
		}else {
			customerMapper.update(entity);
		}
		
	}

	@Override
	public Customer get(Long id) {
		return customerMapper.selectById(id);
	}

	@Override
	public PageInfo<Customer> list(QueryObject qo) { 
		PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
		List<Customer> list = customerMapper.selectAll(qo);
		return new PageInfo<>(list);
	}

	@Override
	public List<Customer> listNotPage(QueryObject qo) {
		List<Customer> list = customerMapper.selectAll(qo);
		return list;
	}

}
